<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<script>
    /*选择价表自动补全*/
    autoCompleteClinic("itemName");
    function autoCompleteClinic(inputId){
        var clinicId = $("#clinicId").val();
        var type = $("#clinicItemClass").val();
        var url="${ctx}/oper/priceList/autoComplete?clinicId="+clinicId+"&type="+type;
        autoComplete(inputId,url,
            function(data){
                var rows = [];
                for(var i=0; i<data.length; i++){
                    rows[rows.length] = {
                        data:data[i],
                        value:data[i].id,
                        result:data[i].itemName
                    };
                }
                return rows;
            },function(data, i, max){
                return data.itemName+"|"+data.itemCode+"|"+data.price+"元 |"+data.label
            },function(event,data,formatted){
                $('#chargeId').attr('value',data.id);
                $('#itemSpec').attr('value',data.itemSpec);
                $('#units').attr('value',data.label);
                $('#price').attr('value',data.price);
                $('#itemClass').attr('value',data.itemClass);
                var amount = $.trim($("#amount").val());
                if(amount!=null&&amount!=''){
                    $("#count").val(Number(amount)*Number(data.price));
                }
            })
    }
</script>
<div class="content-wrap">
    <div class="wrapper" style="bottom: 50px;">
        <ul class="nav nav-tabs">
            <li>
                <a href="#"  onclick="loadDiv('mainCenterDiv','${ctx}/oper/clinicItemDict/index')">诊疗项目列表</a>
            </li>
            <li class="active">
                <a href="#">
                    添加对照
                </a>
            </li>
        </ul>
        <section class="panel panel-default">
            <div class="panel-body">
                <div class="row">
                    <div class="col-lg-7">
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-12">
                                    <form:form  modelAttribute="itemDict" class="form-horizontal">
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">诊疗项目代码：</label>
                                            <div class="col-sm-4">
                                                <input name="ictemCode" readonly class="form-control"  maxlength="50" value="${itemDict.itemCode}"/>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">诊疗项目名称：</label>
                                            <div class="col-sm-4">
                                                <input name="ictemName" readonly class="form-control"  maxlength="200" value="${itemDict.itemName}"/>
                                            </div>
                                        </div>
                                    </form:form>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-lg-12" >
                                    <table id="contentTable" class="table table-bordered mg-t datatable">
                                        <thead>
                                        <tr>
                                            <th>类别</th>
                                            <th>名称</th>
                                            <th>规格</th>
                                            <th>数量</th>
                                            <th>单位</th>
                                            <th>单价</th>
                                            <th>详细类别</th>
                                            <th>小计</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <c:forEach items="${list}" var="baseDto">
                                        <tr>
                                            <td> <c:if test="${baseDto.item_class!='A' and baseDto.item_class!='B'}">非药品</c:if><c:if test="${baseDto.item_class=='A' and baseDto.item_class=='B'}">药品</c:if>  </td>
                                            <td> ${baseDto.item_name}</td>
                                            <td> ${baseDto.item_spec}</td>
                                            <td> ${baseDto.amount}</td>
                                            <td> ${fns:getDictLabel(baseDto.units, 'SPEC_UNIT', '')}</td>
                                            <td> ${baseDto.price}</td>
                                            <td> ${fns:getDictLabel(baseDto.item_class, 'BILL_ITEM_CLASS_DICT', '')}</td>
                                            <td> ${baseDto.totalcount}</td>
                                            <td>
                                                <c:choose>
                                                    <c:when test="${baseDto.gq eq 1}">
                                                        价表已过期
                                                    </c:when>
                                                    <c:when test="${baseDto.ks eq 1}">
                                                        价表未开始
                                                    </c:when>
                                                    <c:otherwise>
                                                        <a href="#"  class="applyBt btn btn-danger btn-xs" onclick="confirmExtend('确认要删除该对照项目吗？',function(){delLoad('mainCenterDiv','${ctx}/oper/clinicVsCharge/delete?chargeId=${baseDto.id}&clinicId=${clinicItemDict.id}','${ctx}/oper/clinicItemDict/addChargeForm?id=${clinicItemDict.id}')})">删除</a>
                                                    </c:otherwise>
                                                </c:choose>
                                            </td>
                                        </tr>
                                        </c:forEach>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-5" >
                        <form:form id="listInputForm" data-parsley-validate="" modelAttribute="clinicItemDict" onsubmit="return formSaveLoad('mainCenterDiv','listInputForm','${ctx}/oper/clinicVsCharge/save','${ctx}/oper/clinicItemDict/addChargeForm?id=${clinicItemDict.id}');" method="post" class="form-horizontal">

                            <input type="hidden" name="clinicId" id="clinicId" value="${clinicItemDict.id}">
                            <input type="hidden" name="chargeId" id="chargeId" >
                            <div class="form-group">
                                <label class="col-sm-2 control-label">类别：</label>
                                <div class="col-sm-4">
                                    <select  id="clinicItemClass" class="form-control" data-parsley-required="true" >
                                        <option value="2">非药品</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">项目名称：</label>
                                <div class="col-sm-4">
                                    <input name="itemName" id="itemName" class="form-control"  maxlength="50" data-parsley-required="true"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">规格：</label>
                                <div class="col-sm-4">
                                    <input name="itemSpec" id="itemSpec" readonly class="form-control"  maxlength="50" data-parsley-required="true"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">数量：</label>
                                <div class="col-sm-4">
                                    <input name="amount" id="amount" value="1" class="form-control"  maxlength="500" data-parsley-type="number" data-parsley-required="true" onblur="return totalCount('amount')"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">单位：</label>
                                <div class="col-sm-4">
                                    <input name="units" id="units" readonly class="form-control"  maxlength="500" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">单价：</label>
                                <div class="col-sm-4">
                                    <input name="price" id="price" readonly class="form-control"  maxlength="500" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">小计：</label>
                                <div class="col-sm-4">
                                    <input name="count" id="count" readonly class="form-control"  maxlength="500" />
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-10">
                                    <input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存">&nbsp;
                                    <input id="btnCancel" class="btn" type="button" value="返 回" onclick="loadDiv('mainCenterDiv','${ctx}/oper/clinicItemDict/index')">
                                </div>
                            </div>
                        </form:form>
                    </div>
                </div>
            </div>
        </section>
    </div>
</div>
<script>
    function totalCount(inputId){
        var amount = $.trim($("#"+inputId).val());
        var price = $.trim($("#price").val());
        if(amount!=null&&amount!=''&&price!=null&&price!=''){
            $("#count").val(Number(amount)*Number(price));
        }

    }
</script>